<?php
/**
 * 飞信机器人--功能插件--历史上的今天
 * 功能：
 * 数据表：
 * 作者： Kelvin
 * 联系： msn:shichangguo@msn.com, qq:191848423
*/
class TodayHistory extends CommonPlugin
{
	var $UUID='0b743a36-1738-4f67-963f-ca5365cbc9b6';
	
	public function TodayHistory(&$session, $pid, $extraPara="")
	{
		parent::__construct($session, $pid, $extraPara);
	}
		
	function getTips()
	{
		return $this->handle('');
	}
	
	public function handle($input)
	{
		if( parent::handleInput($input)) return false;
		
		$url = "http://www1.wst.net.cn/scripts/flex/TodayOnHistory/";
		
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		
		ob_start(); 
		curl_exec($ch);
		$content = ob_get_contents();
		ob_end_clean();
		curl_close($ch);
		$content = iconv('GBK','UTF-8', $content);
		
		$start = "<a href='";
		$end  = "</a>";

		$startPos = 0;

		$arr = array();
		$flag = 0;
		while(1)
		{
			$posStart = strpos($content, $start, $startPos)+strlen($start);
			$posEnd = strpos($content, $end, $posStart);
			if( $posStart-strlen($start) == 0 )break;
			
			$startPos = $posEnd+strlen($posEnd);
			$tmpStr = substr($content, $posStart, $posEnd-$posStart);
			$arr[] = $tmpStr;			
		}		
		array_shift($arr);array_shift($arr);array_shift($arr);array_shift($arr);array_shift($arr);
		
		$content = "";
		for($i=0; $i<count($arr); $i++)
		{
				$arr[$i] = substr($arr[$i], strpos($arr[$i], '>')+1);
				$content.=$arr[$i]."\\n";
		}
			
		return $content.$this->getFooter();
	}	
}

?>
